package com.sport.facilities.booking.system.httptask;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.util.Log;

import com.sport.facilities.booking.system.core.HttpHelper;

public class BasicImageTask extends AsyncTask<String, Void, Bitmap> {
	private final String TAG = "BasicImageTask";
	protected OnTaskCompleted listener;
	Context ctx;
	
    public BasicImageTask(Context ctx,OnTaskCompleted listener) {
        this.ctx = ctx;
        this.listener = listener;
    }

    protected Bitmap doInBackground(String... urls) {
        String urldisplay = urls[0];
        Bitmap bmp = null;
        try {
//            InputStream in = new java.net.URL(urldisplay).openStream();
//            bmp = BitmapFactory.decodeStream(in);
        	HttpHelper httpHelper = new HttpHelper();
            bmp = httpHelper.downloadBitmap(urldisplay);
        } catch (Exception e) {
            e.printStackTrace();
            Log.e(TAG, e.getMessage());
            this.listener.onTaskFailed(e.getMessage());
        }
        return bmp;
        /*
         * HttpHelper httpHelper = new HttpHelper();
         * Bitmap bmp = httpHelper.downloadBitmap("");
         * */
    }

    protected void onPostExecute(Bitmap result) {
        this.listener.onTaskCompleted(result);
    }
}